package com.jd.jobkeeper.client;

import java.util.HashSet;
import java.util.Set;

/**
 * The configuration for job
 */
public class JobConfig {


    /**
     * The application's code
     */
    private String app;

    /**
     * The application's secret token
     */
    private String secretToken;

    /**
     * Namespace code
     */
    private String namespace;

    /**
     * Labels for job client
     */
    private Set<String> labels;

    /**
     * The address index  eg: http://job.com/index
     */
    private String index;

    /**
     * Unit second
     */
    private int refreshAddressInterval = 60;

    /**
     * Directly connect to scheduler cluster , format is ip1:port1,ip2:port2
     */
    private String url;

    public void addLabel(String label) {
        if (labels == null) {
            labels = new HashSet<>();
        }
        labels.add(label);
    }

    public String getApp() {
        return app;
    }

    public void setApp(String app) {
        this.app = app;
    }

    public String getSecretToken() {
        return secretToken;
    }

    public void setSecretToken(String secretToken) {
        this.secretToken = secretToken;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Set<String> getLabels() {
        return labels;
    }

    public void setLabels(Set<String> labels) {
        this.labels = labels;
    }

    public int getRefreshAddressInterval() {
        return refreshAddressInterval;
    }

    public void setRefreshAddressInterval(int refreshAddressInterval) {
        if (refreshAddressInterval < 10) {
            throw new IllegalArgumentException("Parameter refreshAddressInterval must be greater than 10s !");
        }
        this.refreshAddressInterval = refreshAddressInterval;
    }

}
